class GridsController < ApplicationController

  before_filter :grid_authorize, :except => ['index', 'edit']

  def index
    @workshop = Workshop.find(params[:workshop_id])
  end

  
  def new
    @grid = Grid.new(:workshop_id => params[:workshop_id])
  end

  
  def edit
    grid_obj = Grid.find(params[:id])
    @grid = grid_obj.to_json
    @grid_name = grid_obj.name
    @workshop_id = grid_obj.workshop_id
  end

  
  def create
    @grid = Grid.new(params[:grid])

    if @grid.save
      redirect_to(:action => 'edit', :id => @grid.id)
    else
      render :action => 'new'
    end
  end
  
  def destroy
    @grid = Grid.find(params[:id])
    @grid.destroy
    redirect_to(:action => 'index', :workshop_id => params[:workshop_id])
  end

  private

  def grid_authorize
    head :forbidden if !current_user.can_edit_grid
  end

  
end
